We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

$query->save() is not working

Hello,

I have problem with using save() with long text data. In my database json field is set as LONGTEXT. JSON with length 100.000 are saved correctly but save() is not working when json is nearly 1.000.000 Iong. have following code for saving json to database:

<?php

    $json = json_decode(file_get_contents('php://input'),true);
    $events = $data['events'];
    foreach ($events as $event) {
        if($event['type'] != 'aggregate') continue;
        $query = new Backup();
        $query->json = json_encode($event);
        $this->logger("Starting Saving JSON");
        if ($query->save()) {

            $this->logger("JSON was saved.");
            echo "Great, a new data: $query->id was saved successfully!", "\n";
            return $query->id;

        } else {

            $this->logger("JSON was not saved.");
            $messages = '';
            foreach ($query->getMessages() as $message) {
                $messages .= $message->getMessage();
            }

            echo "Umh, We can't store data right now. Reason: " . $messages;

        }
    }

?>

With JSON longer than 1.000.000 I don't get logs after:

<?php
    $this->logger("Starting Saving JSON");
?>

What could be wrong there?

json_decode(file_get_contents('php://input'),true); what is this ? phalcon alreday have builded in methods for getting data from input. Did you have anything in php error log ? Maybe not enough memory or execution time ?

It's get JSON file that's uploaded by API.

I don't have any errors.

Have you checked for PHP errors with error_reporting(E_ALL)? It's probably not an issue with Phalcon, since it works for the first N records then stops without framework errors...